from django.db import models
from django.contrib.auth.models import User

# Create your models here.

class ReviewRecord(models.Model):
    """审查记录表 - 记录所有审核操作"""
    review_type = models.CharField(
        max_length=50,
        null=True,
        blank=True,
        choices=[
            ('extra', '附加分审查'),
            ('punish', '处分审查'),
            ('score', '综测分审查'),
        ],
        verbose_name='审查类型',
        db_comment='审查类型'
    )
    student = models.ForeignKey(
        User,
        on_delete=models.CASCADE,
        null=True,
        blank=True,
        related_name='review_records',
        verbose_name='学生',
        db_comment='学生ID'
    )
    reviewer = models.ForeignKey(
        User,
        on_delete=models.SET_NULL,
        null=True,
        blank=True,
        related_name='reviewed_records',
        verbose_name='审核人',
        db_comment='审核人ID'
    )
    status = models.CharField(
        max_length=20,
        choices=[
            ('pending', '待审核'),
            ('approved', '已通过'),
            ('rejected', '已拒绝'),
        ],
        default='pending',
        verbose_name='审核状态',
        db_comment='审核状态'
    )
    content = models.TextField(blank=True, verbose_name='审核内容', db_comment='审核内容')
    remarks = models.TextField(blank=True, verbose_name='备注', db_comment='备注')
    review_time = models.DateTimeField(null=True, blank=True, verbose_name='审核时间', db_comment='审核时间')
    
    created_at = models.DateTimeField(auto_now_add=True, null=True, blank=True, verbose_name='创建时间', db_comment='创建时间')
    updated_at = models.DateTimeField(auto_now=True, null=True, blank=True, verbose_name='更新时间', db_comment='更新时间')
    
    class Meta:
        db_table = 'zongce_review_record'
        verbose_name = '审查记录'
        verbose_name_plural = '审查记录'
        ordering = ['-created_at']
        db_table_comment = '审查记录表，记录所有类型的审核操作和结果'
    
    def __str__(self):
        return f"{self.get_review_type_display()} - {self.student.username} - {self.get_status_display()}"
